package com.xidian.GMS.controller;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xidian.GMS.dto.Page;
import com.xidian.GMS.entity.JobFair;
import com.xidian.GMS.mapper.JobFairMapper;
import com.xidian.GMS.service.JobFairService;
@Controller

public class JobFairController {

	@Autowired
	  private JobFairMapper JobFairMapper;
	@Autowired
	 private JobFairService  jobFairService;
	@RequestMapping(value="/JobFairEdit",method= RequestMethod.GET)
	public String update0(int jobid ,Model  model){
		    model.addAttribute("jobid", jobid);
			return "JobFairEdit";
			// TODO: handle exception
		
	}


	@RequestMapping(value="/JobFairEdit",method= RequestMethod.POST)
	public String update(
			String jobid,String jobFairName, String starttime, String organizer, String jobFairLocation,
			String jobFairContent){
		int id = Integer.parseInt(jobid);
		Date edittime = new Date();
			jobFairService.update(id,jobFairName, starttime,  organizer, jobFairLocation,
					jobFairContent);
			return "JobFairIndex";
	}

	@RequestMapping(value="/JobFairInsert",method= RequestMethod.POST)
	public String Insert(JobFair jobfair) throws ParseException{
	    System.out.println(123);
		    System.out.println(jobfair);
		try {		
		    jobFairService.Insert(jobfair);
			return "JobFairIndex";
		} catch (Exception e) {
			return "JobFairInsert";
			// TODO: handle exception
		}
		
	}
	@RequestMapping(value="/JobFairInsert",method= RequestMethod.GET)
	public String Insert(){

			return "JobFairInsert";
			// TODO: handle exception
		
		
	}
	@RequestMapping(value="/JobFair",method= RequestMethod.GET)
	public String Insert22(){

			return "JobFair";
			// TODO: handle exception
		
		
	}
	@RequestMapping(value="/JobFairDelete",method= RequestMethod.GET)
	public String delete(int jobfairid){
		try {
		    jobFairService.delete(jobfairid);
			return "forward:/fun3-jobFair.html";
		} catch (Exception e) {
			return "JobFairInsert";
			// TODO: handle exception
		}
		
	}

	@RequestMapping(value="/JobFairIndex",method= RequestMethod.POST)
	public String IndexPost(){

			return "JobFairIndex";
			// TODO: handle exception
		}
		

//	@RequestMapping(value="/JobFairIndex",method= RequestMethod.GET)
//	public String InsertGet(){
//
//			return "JobFairIndex";
//			// TODO: handle exception
//		
//		
//	}
	@RequestMapping(value="/JobFairIndex",method= RequestMethod.GET)
	@ResponseBody
	public Page index(@RequestParam(name="cur", defaultValue="1") int cur, Model model){
		Page page = jobFairService.getJobFair(cur);
		System.out.println(page);
	 	model.addAttribute("page", page);
	 	
			return page;
			// TODO: handle exception
		
		
		
	}
}


